package com.csgc.camera.widget.puzzle

import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.LinearLayout

import com.csgc.camera.widget.IPuzzleUpdate
import com.cysd.spsyxj.R

import com.hjq.shape.view.ShapeView

class PuzzleStyle3:LinearLayout, IPuzzleUpdate {
    private var puzzle1: ShapeView? = null
    private var puzzle2: ShapeView? = null
    private var puzzle3: ShapeView? = null
    private var puzzle4: ShapeView? = null
    private var puzzle5: ShapeView? = null
    private var puzzle6: ShapeView? = null

    constructor(context: Context?) : this(context,null)
    constructor(context: Context?, attrs: AttributeSet?) : this(context, attrs,0)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr){

        LayoutInflater.from(context).inflate(R.layout.include_puzzle_3, this, true)
        puzzle1 = findViewById(R.id.sv_puzzle_6_1)
        puzzle2 = findViewById(R.id.sv_puzzle_6_2)
        puzzle3 = findViewById(R.id.sv_puzzle_6_3)
        puzzle4 = findViewById(R.id.sv_puzzle_6_4)
        puzzle5 = findViewById(R.id.sv_puzzle_6_5)
        puzzle6 = findViewById(R.id.sv_puzzle_6_6)
    }

    override fun update(count:Int) {
        if (count == 0){
            puzzle1?.shapeDrawableBuilder?.setSolidColor(Color.TRANSPARENT)?.intoBackground()
            puzzle2?.shapeDrawableBuilder?.setSolidColor(Color.TRANSPARENT)?.intoBackground()
            puzzle3?.shapeDrawableBuilder?.setSolidColor(Color.TRANSPARENT)?.intoBackground()
            puzzle4?.shapeDrawableBuilder?.setSolidColor(Color.TRANSPARENT)?.intoBackground()
            puzzle5?.shapeDrawableBuilder?.setSolidColor(Color.TRANSPARENT)?.intoBackground()
            puzzle6?.shapeDrawableBuilder?.setSolidColor(Color.TRANSPARENT)?.intoBackground()

        }else{
            for (i in 1 .. count){
                if (i == 1){
                    puzzle1?.shapeDrawableBuilder?.setSolidColor(Color.WHITE)?.intoBackground()
                    puzzle2?.shapeDrawableBuilder?.setSolidColor(Color.TRANSPARENT)?.intoBackground()
                }else if(i == 2){
                    puzzle2?.shapeDrawableBuilder?.setSolidColor(Color.WHITE)?.intoBackground()
                    puzzle3?.shapeDrawableBuilder?.setSolidColor(Color.TRANSPARENT)?.intoBackground()
                }else if(i == 3){
                    puzzle3?.shapeDrawableBuilder?.setSolidColor(Color.WHITE)?.intoBackground()
                    puzzle4?.shapeDrawableBuilder?.setSolidColor(Color.TRANSPARENT)?.intoBackground()
                }else if(i == 4){
                    puzzle4?.shapeDrawableBuilder?.setSolidColor(Color.WHITE)?.intoBackground()
                    puzzle5?.shapeDrawableBuilder?.setSolidColor(Color.TRANSPARENT)?.intoBackground()

                }else if(i == 5){
                    puzzle5?.shapeDrawableBuilder?.setSolidColor(Color.WHITE)?.intoBackground()
                    puzzle6?.shapeDrawableBuilder?.setSolidColor(Color.TRANSPARENT)?.intoBackground()

                }else if(i == 6){
                    puzzle6?.shapeDrawableBuilder?.setSolidColor(Color.WHITE)?.intoBackground()

                }
            }

        }
    }


}